package controller

import (
	"alan-snippet/internal/dto"
	"alan-snippet/internal/models"
	"alan-snippet/internal/response"
	"alan-snippet/internal/service"

	"github.com/gin-gonic/gin"
)

func ListTags(c *gin.Context) {
	tags, err := service.ListTags()
	if err != nil {
		response.FailWithCode(c, response.ErrCodeInternal)
		return
	}

	tagsRes := make([]*dto.TagResponseDTO, 0, len(tags))
	for _, tag := range tags {
		tagsRes = append(tagsRes, modelToTagResponseDTO(tag))
	}

	response.OkWithData(c, tagsRes)
}

func modelToTagResponseDTO(tag *models.Tag) *dto.TagResponseDTO {
	return &dto.TagResponseDTO{
		ID:   tag.ID,
		Name: tag.Name,
	}
}
